<template>
  <div class="app-container calendar-list-container" @click="querySet">
    <div class="yt-data-list" style="margin: -20px -20px 0 -20px; : none;">
      <div class="yt-list-title" style=" : none;padding-left: 40px">
        <span>{{$t('myDailyDetails.fillInDaily')}}</span>
      </div>
    </div>
    <!-- Daily Report -->
    <div class="data-list" style="position: relative">
      <div class="list-content" style="height: 50px;line-height: 50px">
        <span style="line-height: 46px">Daily Report</span>
      </div>
      <div class="block absolute">
        <span class="demonstration">*Date</span>
        <!--:readonly="isDailyDate"-->
        <el-date-picker v-model="dailyDate" :disabled="isEdit" :clearable="false" type="date" value-format="yyyy-MM-dd" @change="changeDate" :placeholder="$t('myDailyDetails.placeholder.paeaseDate')"></el-date-picker>
      </div>
      <div class="list-operation">
        <!--新增当前日报-->
        <el-button v-if="!isEdit" class="yt-btn-ys" type="primary" @click="add('dailyReport')">{{$t('myDailyDetails.add')}}</el-button>
        <el-button v-if="!isEdit" class="yt-btn" type="primary" @click="handleDelete('dailyReport')">{{$t('myDailyDetails.delete')}}</el-button>
        <el-button v-if="!isEdit" class="yt-btn" type="primary" @click="copyPlan">{{$t('myDailyDetails.planAdd')}}</el-button>
      </div>
      <el-table :data="dailyReportList"
                :empty-text="$t('placeholder.emptyText')"
                class="yt-table yt-temporary" @selection-change="selectDailyReport"
                style="width: 100%; overflow-x: visible" max-height="435">
        <el-table-column align="center" label="Total">
          <el-table-column type="selection" align="center" prop="id" width="60" />
          <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
        </el-table-column>
        <el-table-column align="center">
          <el-table-column align="center" label="*Client" width="200" prop="customerName">
            <template slot-scope="scope">
              <div style="display: flex;align-content: center;justify-content: center">
                <el-checkbox style="padding: 8px 8px 0 5px" true-label="1" label="0" false-label="0" @change="clearCustomer('dailyReport',scope.$index,$event)" :disabled="isEdit" v-model="scope.row.customerIs">N/A</el-checkbox>
                <el-popover :disabled="isEdit"  trigger="focus" width="600" placement="right-start" v-if="scope.row.customerIs !== '1'">
                  <el-table :data="optionsCustomer" border :empty-text="$t('placeholder.emptyText')" class="yt-table" style="width: 100%;margin-top: 20px"  >
                    <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
                    <el-table-column align="center" :label="$t('myDailyDetails.Client.customerNo')" prop="customerNo"/>
                    <el-table-column align="center" :label="$t('myDailyDetails.Client.customerName')" prop="customerName" width="200"/>
                    <el-table-column align="center" :label="$t('myDailyDetails.Client.customerShortName')" prop="customerShortName"/>
                    <el-table-column align="center" :label="$t('myDailyDetails.Client.handle')">
                      <template slot-scope="scopes">
                        <el-button size="mini" @click="select('dailyReport',scope.$index,scopes.row)">{{$t('myDailyDetails.Client.select')}}</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                  <el-input slot="reference" :disabled="isEdit" :placeholder="$t('myDailyDetails.placeholder.searchKeywords')" :clearable="!isEdit" v-model="scope.row.customerName" @focus="queryList('dailyReport',scope.$index,scope.row)" v-on:input ="queryList('dailyReport',scope.$index,scope.row)"></el-input>
                </el-popover>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column align="center">
          <el-table-column align="center" label="*Type" width="60" prop="dailyReportType">
            <template slot-scope="scope">
              <yt-select style="height:36px" @selectedChange="clearDescription('dailyReport',scope.$index)"  v-model="scope.row.dailyReportType" :disabled="!isEdit && scope.row.customerIs !== '1' ? false : true" :listData="scope.row.customerName?dailyReportTypeListShort:dailyReportTypeList"></yt-select>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column align="center">
          <el-table-column align="center" label="* Project/Description" width="300" prop="description">
            <template slot-scope="scope">
              <el-popover trigger="manual" width="700" :disabled="isEdit" placement="bottom-start" v-model="scope.row.visible" v-if="scope.row.dailyReportType === '0' || scope.row.dailyReportType === '1'">
                <el-input v-model="scope.row.queryDescription"
                          :placeholder="$t('myDailyDetails.placeholder.searchKeywords')"
                          v-on:input ="queryProjectDescription('dailyReport',scope.$index,scope.row.queryDescription,scope.row.dailyReportType)"
                          :clearable="!isEdit">
                  <i slot="prefix" class="el-input__icon el-icon-search"></i>
                </el-input>
                <el-table :data="projectDescription" border :empty-text="$t('placeholder.emptyText')" class="yt-table" style="width: 100%;margin-top: 20px"  >
                  <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.projectDescription.clientName')" prop="clientName"/>
                  <el-table-column v-if="scope.row.dailyReportType === '0'" align="center" :label="$t('myDailyDetails.projectDescription.projectName')" prop="projectName"/>
                  <el-table-column v-if="scope.row.dailyReportType === '0'" align="center" :label="$t('myDailyDetails.projectDescription.projectNo')" prop="projectNo"/>
                  <el-table-column v-if="scope.row.dailyReportType === '1'" align="center" :label="$t('myDailyDetails.projectDescription.bdName')" prop="bdName"/>
                  <el-table-column v-if="scope.row.dailyReportType === '1'" align="center" :label="$t('myDailyDetails.projectDescription.bdNo')" prop="bdNo"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.projectDescription.handle')">
                    <template slot-scope="scopes">
                      <el-button size="mini" @click="selectProjectDescription('dailyReport', scope.$index,scopes.row)">{{$t('myDailyDetails.projectDescription.select')}}</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-input slot="reference" type="textarea" autosize
                          :disabled="isEdit"
                          :readonly="scope.row.dailyReportType === '0' || scope.row.dailyReportType === '1' ? true : false"
                          :placeholder="$t('myDailyDetails.placeholder.pleaseSelect')"
                          @click.stop.native="queryProjectDescription('dailyReport',scope.$index,scope.row.queryDescription,scope.row.dailyReportType)"
                          :clearable="!isEdit" v-model="scope.row.description"
                          style="-ms-overflow-y: hidden; -ms-overflow-x: hidden">
                </el-input>
              </el-popover>
              <div style="display: flex;">
                <div>
                  <dict-select v-show="scope.row.dailyReportType === '2'" v-model="scope.row.description" :disabled="isEdit" code="hqType" :clearable="!isEdit"></dict-select>
                </div>
                <el-input type="textarea" autosize
                          v-if="scope.row.customerIs === '1'"
                          :disabled="isEdit"
                          :placeholder="$t('myDailyDetails.placeholder.pleaseImport')"
                          style="-ms-overflow-y: hidden; -ms-overflow-x: hidden"
                          :clearable="!isEdit" v-model="scope.row.other"></el-input>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column align="center">
          <el-table-column align="center" label="*Action Item" prop="actionItem">
            <template slot-scope="scope">
              <el-input type="textarea" autosize :placeholder="$t('myDailyDetails.placeholder.pleaseImport')"
                        style="-ms-overflow-y: hidden; -ms-overflow-x: hidden"
                        :disabled="isEdit" v-model="scope.row.actionItem"></el-input>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column align="center" :label="dailyReportList[0] ? dailyReportList[0].sumTotal.hrs+'' : ''">
          <el-table-column align="center" label="* Hrs" width="60" prop="hrs">
            <template slot-scope="scope">
              <el-input :disabled="isEdit" type="Number" :placeholder="$t('myDailyDetails.placeholder.pleaseImport')" v-model="scope.row.hrs" @change="changes('dailyReport',scope.$index,$event)"></el-input>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column align="center">
          <el-table-column align="center" label="Project Amount" width="120" prop="projectAmount">
            <template slot-scope="scope">
              <div v-format="'#,##0'">{{scope.row.projectAmount}}</div>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
    <!-- Plan activity -->
    <div class="data-list" style="position: relative">
      <div class="list-content" style="height: 50px;line-height: 50px">
        <span style="line-height: 46px">Plan activity</span>
      </div>
      <div class="block absolute">
        <span class="demonstration">*Date</span>
        <el-date-picker v-model="dailyPlanDate" :disabled="isEdit" :clearable="false" type="date" value-format="yyyy-MM-dd"></el-date-picker> <!--// value-format="yyyy-MM-dd"-->
      </div>
      <div class="list-operation">
        <!--新增计划日报-->
        <el-button v-if="!isEdit" class="yt-btn-ys" type="primary" @click="add('dailyReportPlan')">{{$t('myDailyDetails.add')}}</el-button>
        <el-button v-if="!isEdit" class="yt-btn"  @click="handleDelete('dailyReportPlan')" type="primary">{{$t('myDailyDetails.delete')}}</el-button>
      </div>
      <el-table :data="dailyReportPlanList" :empty-text="$t('placeholder.emptyText')" @selection-change="selectDailyReportPlan" class="yt-table yt-temporary" style="width: 100%" max-height="405">
        <el-table-column type="selection" align="center" prop="id" width="60"/>
        <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
        <el-table-column align="center" label="*Client" width="200" prop="customerName">
          <template slot-scope="scope">
            <div style="display: flex;align-content: center;justify-content: center">
              <el-checkbox style="padding: 8px 8px 0 5px" true-label="1" label="0" false-label="0" @change="clearCustomer('dailyReportPlan',scope.$index)" :disabled="isEdit" v-model="scope.row.customerIs">N/A</el-checkbox>
              <el-popover :disabled="isEdit" trigger="focus" width="600" placement="right-start" v-if="scope.row.customerIs !== '1'">
                <el-table :data="optionsCustomer" border :empty-text="$t('placeholder.emptyText')" class="yt-table" style="width: 100%;margin-top: 20px"  >
                  <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.Client.customerNo')" prop="customerNo"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.Client.customerName')" prop="customerName" width="200"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.Client.customerShortName')" prop="customerShortName"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.Client.handle')">
                    <template slot-scope="scopes">
                      <el-button size="mini" @click="select('dailyReportPlan',scope.$index,scopes.row)">{{$t('myDailyDetails.Client.select')}}</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-input slot="reference" :disabled="isEdit" :placeholder="$t('myDailyDetails.placeholder.searchKeywords')" :clearable="!isEdit" v-model="scope.row.customerName" @focus="queryList('dailyReportPlan',scope.$index,scope.row)" v-on:input ="queryList('dailyReportPlan',scope.$index,scope.row)"></el-input>
              </el-popover>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="*Type" width="60" prop="dailyReportType">
          <template slot-scope="scope">
            <yt-select style="height:36px" @selectedChange="clearDescription('dailyReportPlan',scope.$index)" :disabled="!isEdit && scope.row.customerIs !== '1' ? false : true" v-model="scope.row.dailyReportType" :listData="scope.row.customerName?dailyReportTypeListShort:dailyReportTypeList"></yt-select>
          </template>
        </el-table-column>
        <el-table-column align="center" label="* Project/Description" width="300" prop="description">
          <template slot-scope="scope">
            <el-popover trigger="manual" width="600" :disabled="isEdit" placement="bottom-start" v-model="scope.row.visible" v-if="scope.row.dailyReportType === '0' || scope.row.dailyReportType === '1'">
              <el-input v-model="scope.row.queryDescription" :placeholder="$t('myDailyDetails.placeholder.searchKeywords')" v-on:input ="queryProjectDescription('dailyReportPlan',scope.$index,scope.row.queryDescription,scope.row.dailyReportType)" :clearable="!isEdit">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
              </el-input>
              <el-table :data="projectDescription" border :empty-text="$t('placeholder.emptyText')" class="yt-table" style="width: 100%;margin-top: 20px" >
                <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
                <el-table-column align="center" :label="$t('myDailyDetails.projectDescription.clientName')" prop="clientName"/>
                <el-table-column v-if="scope.row.dailyReportType === '0'" align="center" :label="$t('myDailyDetails.projectDescription.projectName')" prop="projectName"/>
                <el-table-column v-if="scope.row.dailyReportType === '0'" align="center" :label="$t('myDailyDetails.projectDescription.projectNo')" prop="projectNo"/>
                <el-table-column v-if="scope.row.dailyReportType === '1'" align="center" :label="$t('myDailyDetails.projectDescription.bdName')" prop="bdName"/>
                <el-table-column v-if="scope.row.dailyReportType === '1'" align="center" :label="$t('myDailyDetails.projectDescription.bdNo')" prop="bdNo"/>
                <el-table-column align="center" :label="$t('myDailyDetails.projectDescription.handle')">
                  <template slot-scope="scopes">
                    <el-button size="mini" @click="selectProjectDescription('dailyReportPlan', scope.$index,scopes.row)">{{$t('myDailyDetails.projectDescription.select')}}</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <el-input slot="reference" type="textarea" autosize :placeholder="$t('myDailyDetails.placeholder.pleaseSelect')" :disabled="isEdit"
              :readonly="scope.row.dailyReportType === '0' || scope.row.dailyReportType === '1' ? true : false" :clearable="!isEdit"
              v-model="scope.row.description" style="-ms-overflow-y: hidden; -ms-overflow-x: hidden"
              @click.stop.native="queryProjectDescription('dailyReportPlan',scope.$index,scope.row.description,scope.row.dailyReportType)"></el-input>
            </el-popover>
            <div style="display: flex;">
              <div>
                <dict-select v-show="scope.row.dailyReportType === '2'" v-model="scope.row.description" :disabled="isEdit" code="hqType" :clearable="!isEdit"></dict-select>
              </div>
              <el-input type="textarea" autosize v-if="scope.row.customerIs === '1'"
                        :disabled="isEdit" :placeholder="$t('myDailyDetails.placeholder.pleaseImport')"
                        :clearable="!isEdit" v-model="scope.row.other"
                        style="-ms-overflow-y: hidden; -ms-overflow-x: hidden"></el-input>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="Action Item" prop="actionItem">
          <template slot-scope="scope">
            <el-input type="textarea" autosize
                      :placeholder="$t('myDailyDetails.placeholder.pleaseImport')"
                      :disabled="isEdit"
                      style="-ms-overflow-y: hidden; -ms-overflow-x: hidden"
                      v-model="scope.row.actionItem"></el-input>
          </template>
        </el-table-column>
        <el-table-column align="center" label="Hrs" width="60" prop="hrs">
          <template slot-scope="scope">
            <el-input type="Number" :placeholder="$t('myDailyDetails.placeholder.pleaseImport')" :disabled="isEdit" v-model="scope.row.hrs" @change="changes('dailyReportPlan',scope.$index,$event)"></el-input>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- Tracking Item -->
    <div class="data-list" style="position: relative">
      <div class="list-content">
        <span>Tracking Item</span>
      </div>
      <div class="list-operation">
        <el-button v-if="!isEdit" class="yt-btn-ys" type="primary" @click="add('preDailyReport')">{{$t('myDailyDetails.add')}}</el-button>
        <el-button v-if="!isEdit" class="yt-btn"  @click="handleDelete('preDailyReport')" type="primary">{{$t('myDailyDetails.delete')}}</el-button>
      </div>
      <!--上次日报内容-->
      <el-table :data="preDailyReportList" :empty-text="$t('placeholder.emptyText')" @selection-change="selectPreDailyReport" class="yt-table yt-temporary" style="width: 100%;overflow-x: visible" max-height="405">
        <el-table-column type="selection" align="center" prop="id" width="60"/>
        <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
        <el-table-column align="center" label="Client" width="200" prop="customerName">
          <template slot-scope="scope">
            <div style="display: flex;align-content: center;justify-content: center">
              <el-checkbox style="padding: 8px 8px 0 5px" true-label="1" label="0" false-label="0" @change="clearCustomer('preDailyReport',scope.$index)" :disabled="isEdit" v-model="scope.row.customerIs">N/A</el-checkbox>
              <el-popover :disabled="isEdit" trigger="focus" width="600" placement="right-start" v-if="scope.row.customerIs !=='1'">
                <el-table :data="optionsCustomer" border :empty-text="$t('placeholder.emptyText')" class="yt-table" style="width: 100%;margin-top: 20px" >
                  <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.Client.customerNo')" prop="customerNo"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.Client.customerName')" prop="customerName" width="200"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.Client.customerShortName')" prop="customerShortName"/>
                  <el-table-column align="center" :label="$t('myDailyDetails.Client.handle')">
                    <template slot-scope="scopes">
                      <el-button size="mini" @click="select('preDailyReport',scope.$index,scopes.row)">{{$t('myDailyDetails.Client.select')}}</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-input slot="reference" :disabled="isEdit" :placeholder="$t('myDailyDetails.placeholder.searchKeywords')" :clearable="!isEdit" v-model="scope.row.customerName" @focus="queryList('preDailyReport',scope.$index,scope.row)" v-on:input ="queryList('preDailyReport',scope.$index,scope.row)"></el-input>
              </el-popover>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="Type" width="60" prop="dailyReportType">
          <template slot-scope="scope">
            <yt-select style="height:36px" @selectedChange="clearDescription('preDailyReport',scope.$index)" :disabled="!isEdit && scope.row.customerIs !== '1' ? false : true" v-model="scope.row.dailyReportType" :listData="scope.row.customerName?dailyReportTypeListShort:dailyReportTypeList"></yt-select>
          </template>
        </el-table-column>
        <el-table-column align="center" label="Project/Description" width="300" prop="description">
          <template slot-scope="scope">
            <el-popover trigger="manual" width="600" :disabled="isEdit" placement="bottom-start" v-model="scope.row.visible" v-if="scope.row.dailyReportType === '0' || scope.row.dailyReportType === '1'">
              <el-input v-model="scope.row.queryDescription" :placeholder="$t('myDailyDetails.placeholder.searchKeywords')" v-on:input ="queryProjectDescription('preDailyReport',scope.$index,scope.row.queryDescription,scope.row.dailyReportType)" :clearable="!isEdit">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
              </el-input>
              <el-table :data="projectDescription" border :empty-text="$t('placeholder.emptyText')" class="yt-table" style="width: 100%;margin-top: 20px"  >
                <el-table-column type="index" align="center" :label="$t('myDailyDetails.index')" width="60"/>
                <el-table-column align="center" :label="$t('myDailyDetails.projectDescription.clientName')" prop="clientName"/>
                <el-table-column v-if="scope.row.dailyReportType === '0'" align="center" :label="$t('myDailyDetails.projectDescription.projectName')" prop="projectName"/>
                <el-table-column v-if="scope.row.dailyReportType === '0'" align="center" :label="$t('myDailyDetails.projectDescription.projectNo')" prop="projectNo"/>
                <el-table-column v-if="scope.row.dailyReportType === '1'" align="center" :label="$t('myDailyDetails.projectDescription.bdName')" prop="bdName"/>
                <el-table-column v-if="scope.row.dailyReportType === '1'" align="center" :label="$t('myDailyDetails.projectDescription.bdNo')" prop="bdNo"/>
                <el-table-column align="center" :label="$t('myDailyDetails.projectDescription.handle')">
                  <template slot-scope="scopes">
                    <el-button size="mini" @click="selectProjectDescription('preDailyReport', scope.$index,scopes.row)">{{$t('myDailyDetails.projectDescription.select')}}</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <el-input slot="reference" type="textarea" autosize
                        :placeholder="$t('myDailyDetails.placeholder.pleaseSelect')" :disabled="isEdit"
                        :readonly="scope.row.dailyReportType === '0' || scope.row.dailyReportType === '1' ? true : false"
                        :clearable="!isEdit" v-model="scope.row.description"
                        @click.stop.native="queryProjectDescription('preDailyReport',scope.$index,scope.row.description,scope.row.dailyReportType)"
                        style="-ms-overflow-y: hidden; -ms-overflow-x: hidden"></el-input>
            </el-popover>
            <div style="display: flex;">
              <div>
              <dict-select v-show="scope.row.dailyReportType === '2'" v-model="scope.row.description" :disabled="isEdit" code="hqType" :clearable="!isEdit"></dict-select>
              </div>
              <el-input type="textarea" autosize
                        v-if="scope.row.customerIs === '1'" :disabled="isEdit"
                        :placeholder="$t('myDailyDetails.placeholder.pleaseImport')"
                        style="-ms-overflow-y: hidden; -ms-overflow-x: hidden"
                        :clearable="!isEdit" v-model="scope.row.other"></el-input>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="Action Item" prop="actionItem">
          <template slot-scope="scope">
            <el-input type="textarea" autosize style="-ms-overflow-y: hidden; -ms-overflow-x: hidden" v-model="scope.row.actionItem" :disabled="isEdit"></el-input>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="data-bnt">
      <el-row>
        <el-col>
          <el-button class="yt-btn" type="primary" @click="backPageCopy()">{{isEdit? $t('myDailyDetails.getBack') : $t('myDailyDetails.cancel')}}</el-button>
          <el-button class="yt-btn" type="primary" v-if="!isEdit" @click="submit('0')">{{$t('myDailyDetails.draft')}}</el-button>
          <el-button class="yt-btn-ys" type="primary" v-if="!isEdit" @click="submit('1')">{{$t('myDailyDetails.submit')}}</el-button>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
  import { queryDetail, queryClient, getProjectByClient, getDemandByClient, getNextDay, save, queryPreDaily, queryPlan } from '@/api/dailyAdministrator/myDaily';
  import formatter from '@/utils/formatter';
  import YtSelect from '@/components/Yt-select/index.vue';
  import dictSelect from '@/components/Dict/dictValueSelect.vue';
  import store from '@/store'
  export default {
    name: 'myDailyDetails',
    components: {
      YtSelect,
      dictSelect
    },
    data() {
      return {
        show: false,
        isEdit: false,
        coumt: 0,
        dailyReportTypeList: this.$store.getters.allDic.dailyType,
        dailyReportTypeListShort: [],
        formatter,
        id: '',
        isDailyDate: false,
        dailyDate: null,
        dailyPlanDate: null,
        daily: {},
        total: {},
        selectDailyReportPlanList: [],
        selectDailyReportList: [],
        selectPreDailyReportList: [],
        dailyReportList: [], // 当前日报
        dailyReportPlanList: [], // 计划日报
        preDailyReportList: [], // 上次的日报
        optionsCustomer: [],
        projectDescription: []
      };
    },
    watch: {
      dailyDate(netVal) {
        if (!this.id) {
          queryPreDaily({ dailyDate: netVal }).then(res => {
            this.preDailyReportList = res.data
            for (let y = 0; y < this.preDailyReportList.length; y++) {
              this.preDailyReportList[y].listIndex = y;
            }
          })
        }
      }
    },
    methods: {
      clearDescription(str, index) {
        if (str === 'dailyReport') {
          this.dailyReportList[index].description = ''
        } else if (str === 'dailyReportPlan') {
          this.dailyReportPlanList[index].description = ''
        } else {
          this.preDailyReportList[index].description = ''
        }
      },
      querySet() {
        if (this.dailyReportList[this.coumt]) {
          this.$set(this.dailyReportList[this.coumt], 'visible', false)
        }
        if (this.dailyReportPlanList[this.coumt]) {
          this.$set(this.dailyReportPlanList[this.coumt], 'visible', false)
        }
        if (this.preDailyReportList[this.coumt]) {
          this.$set(this.preDailyReportList[this.coumt], 'visible', false)
        }
      },
      // total
      sumTotal() {
        const _this = this
        this.total = {}
        this.dailyReportList.forEach(row => {
          Object.keys(row).forEach(key => {
            // 总计
            if (!_this.total.hasOwnProperty(key)) {
              _this.total[key] = 0
            }
            if (key !== 'hrs') {
              _this.total[key]++
            } else {
              if (row[key] && _this.total[key] >= 0) {
                _this.total[key] = Number(_this.total[key]) + Number(row[key])

                const value = Number.parseFloat(_this.total[key])
                const valueStr = value.toString()

                if (valueStr.indexOf('.') !== -1 && valueStr.split('.')[1].length > 2) {
                  _this.total[key] = value.toFixed(2)
                }
              }
            }
          })
        })
        this.$set(this.dailyReportList[0], 'sumTotal', _this.total)
      },
      changeDate() {
        getNextDay({ dailyDate: this.dailyDate }).then(res => {
          this.dailyPlanDate = res.data
        })
      },
      add(str) {
        this.total = {}
        if (str === 'dailyReport') {
          const dataList = {
            listIndex: this.dailyReportList.length,
            customerId: '', // 客户Id
            customerName: '', // 客户名称
            dailyReportType: '', // 类型
            description: '', // Project/Description
            itemId: '',
            actionItem: '', // Action Item
            hrs: '',
            projectAmount: ''
          };
          this.$set(this.dailyReportList, this.dailyReportList.length, dataList);
          this.sumTotal()
        } else if (str === 'dailyReportPlan') {
          const dataList = {
            listIndex: this.dailyReportPlanList.length,
            customerId: '', // 客户Id
            customerName: '', // 客户名称
            dailyReportType: '', // 类型
            description: '', // Project/Description
            itemId: '',
            actionItem: '', // Action Item
            hrs: '',
            projectAmount: ''
          };
          this.$set(this.dailyReportPlanList, this.dailyReportPlanList.length, dataList);
          // this.sumTotal()
        } else {
          const dataList = {
            listIndex: this.preDailyReportList.length,
            customerId: '', // 客户Id
            customerName: '', // 客户名称
            dailyReportType: '', // 类型
            description: '', // Project/Description
            itemId: '',
            actionItem: '', // Action Item
            hrs: '',
            projectAmount: ''
          };
          this.$set(this.preDailyReportList, this.preDailyReportList.length, dataList);
          // this.sumTotal()
        }
      },
      changes(title, index, val) {
        this.total = {}
        if (title === 'dailyReport') {
          if (val > 8) {
            this.dailyReportList[index].hrs = 8
          }
        } else {
          if (val > 8) {
            this.dailyReportPlanList[index].hrs = 8
          }
        }
        this.sumTotal()
      },
      selectDailyReport(val) {
        //  表格序号选中函数
        this.selectDailyReportList = val;
      },
      selectDailyReportPlan(val) {
        //  表格序号选中函数
        this.selectDailyReportPlanList = val;
      },
      selectPreDailyReport(val) {
        //  表格序号选中函数
        this.selectPreDailyReportList = val;
      },
      // 删除
      handleDelete(sir) {
        if (sir === 'dailyReport') {
          if (this.selectDailyReportList.length > 0) {
            console.log(JSON.stringify(this.selectDailyReportList))
            this.selectDailyReportList.forEach(x => {
              this.dailyReportList.splice(
                this.dailyReportList.findIndex(item => item.listIndex === x.listIndex),
                1
              );
            });
            this.sumTotal();

            for (let y = 0; y < this.dailyReportList.length; y++) {
              this.dailyReportList[y].listIndex = y;
            }
          } else {
            this.$message.error(this.$t('myDailyDetails.message.hint'));
          }
        } else if (sir === 'dailyReportPlan') {
          if (this.selectDailyReportPlanList.length > 0) {
            this.selectDailyReportPlanList.forEach(x => {
              this.dailyReportPlanList.splice(
                this.dailyReportPlanList.findIndex(item => item.listIndex === x.listIndex),
                1
              );
            });
            for (let y = 0; y < this.dailyReportPlanList.length; y++) {
              this.dailyReportPlanList[y].listIndex = y;
            }
          } else {
            this.$message.error(this.$t('myDailyDetails.message.hint'));
          }
        } else {
          if (this.selectPreDailyReportList.length > 0) {
            this.selectPreDailyReportList.forEach(x => {
              this.preDailyReportList.splice(
                this.preDailyReportList.findIndex(item => item.listIndex === x.listIndex),
                1
              );
            });
            for (let y = 0; y < this.preDailyReportList.length; y++) {
              this.preDailyReportList[y].listIndex = y;
            }
          } else {
            this.$message.error(this.$t('myDailyDetails.message.hint'));
          }
        }
      },
      queryList(sir, index, row) {
        if (sir === 'dailyReport') {
          if (this.dailyReportList[index].customerName !== this.dailyReportList[index].customerNameOld) {
            this.dailyReportList[index].customerId = ''
          }
          if (row.customerName === '') {
            this.dailyReportList[index].dailyReportType = ''
            this.dailyReportList[index].description = ''
          }
        } else if (sir === 'dailyReportPlan') {
          if (this.dailyReportPlanList[index].customerName !== this.dailyReportPlanList[index].customerNameOld) {
            this.dailyReportPlanList[index].customerId = ''
          }
          if (row.customerName === '') {
            this.dailyReportPlanList[index].dailyReportType = ''
            this.dailyReportPlanList[index].description = ''
          }
        } else {
          if (this.preDailyReportList[index].customerName !== this.preDailyReportList[index].customerNameOld) {
            this.preDailyReportList[index].customerId = ''
          }
          if (row.customerName === '') {
            this.preDailyReportList[index].dailyReportType = ''
            // this.preDailyReportList[index].description = ''
          }
        }
        queryClient({ clientName: row.customerName }).then(res => {
          this.optionsCustomer = res.data.rows
        });
      },
      select(sir, index, row) {
        if (sir === 'dailyReport') {
          this.dailyReportList[index].customerId = row.id
          this.dailyReportList[index].customerName = row.customerShortName
          this.dailyReportList[index].customerNameOld = row.customerShortName

          this.dailyReportList[index].description = ''
          this.dailyReportList[index].projectAmount = ''
          this.dailyReportList[index].itemId = ''
        } else if (sir === 'dailyReportPlan') {
          this.dailyReportPlanList[index].customerId = row.id
          this.dailyReportPlanList[index].customerName = row.customerShortName
          this.dailyReportPlanList[index].customerNameOld = row.customerShortName

          this.dailyReportPlanList[index].description = ''
          this.dailyReportPlanList[index].projectAmount = ''
          this.dailyReportPlanList[index].itemId = ''
        } else {
          this.preDailyReportList[index].customerId = row.id
          this.preDailyReportList[index].customerName = row.customerShortName
          this.preDailyReportList[index].customerNameOld = row.customerShortName

          this.preDailyReportList[index].description = ''
          this.preDailyReportList[index].projectAmount = ''
          this.preDailyReportList[index].itemId = ''
        }
      },
      clearCustomer(sir, index) {
        if (sir === 'dailyReport') {
          this.dailyReportList[index].other = ''
          this.dailyReportList[index].customerId = ''
          this.dailyReportList[index].customerName = ''

          this.dailyReportList[index].description = ''
          this.dailyReportList[index].projectAmount = ''
          this.dailyReportList[index].itemId = ''
          if (this.dailyReportList[index].customerIs === '1') {
            this.dailyReportList[index].dailyReportType = '2'
          } else {
            this.dailyReportList[index].dailyReportType = ''
          }
        } else if (sir === 'dailyReportPlan') {
          this.dailyReportPlanList[index].other = ''
          this.dailyReportPlanList[index].customerId = ''
          this.dailyReportPlanList[index].customerName = ''

          this.dailyReportPlanList[index].description = ''
          this.dailyReportPlanList[index].projectAmount = ''
          this.dailyReportPlanList[index].itemId = ''
          if (this.dailyReportPlanList[index].customerIs === '1') {
            this.dailyReportPlanList[index].dailyReportType = '2'
          } else {
            this.dailyReportPlanList[index].dailyReportType = ''
          }
        } else {
          this.preDailyReportList[index].other = ''
          this.preDailyReportList[index].customerId = ''
          this.preDailyReportList[index].customerName = ''

          this.preDailyReportList[index].description = ''
          this.preDailyReportList[index].projectAmount = ''
          this.preDailyReportList[index].itemId = ''
          if (this.preDailyReportList[index].customerIs === '1') {
            this.preDailyReportList[index].dailyReportType = '2'
          } else {
            this.preDailyReportList[index].dailyReportType = ''
          }
        }
      },
      queryProjectDescription(sir, index, query, type) {
        this.projectDescription = []
        if (sir === 'dailyReport') {
          const obj = {
            clientId: this.dailyReportList[index].customerId !== '' ? this.dailyReportList[index].customerId : '',
            queryStr: query ? query : '',
            limit: '5'
          }
          if (type === '0') {
            getProjectByClient(obj).then(res => {
              this.projectDescription = res.data.rows
            })
          } else if (type === '1') {
            getDemandByClient(obj).then(res => {
              this.projectDescription = res.data.rows
            })
          }

          this.$set(this.dailyReportList[index], 'visible', true)
          this.coumt = index
        } else if (sir === 'dailyReportPlan') {
          const obj = {
            clientId: this.dailyReportPlanList[index].customerId ? this.dailyReportPlanList[index].customerId : '',
            queryStr: query ? query : '',
            limit: '5'
          }
          if (type === '0') {
            getProjectByClient(obj).then(res => {
              this.projectDescription = res.data.rows
            })
          } else if (type === '1') {
            getDemandByClient(obj).then(res => {
              this.projectDescription = res.data.rows
            })
          }
          this.$set(this.dailyReportPlanList[index], 'visible', true)
          this.coumt = index
        } else {
          const obj = {
            clientId: this.preDailyReportList[index].customerId ? this.preDailyReportList[index].customerId : '',
            queryStr: query ? query : '',
            limit: '5'
          }
          if (type === '0') {
            getProjectByClient(obj).then(res => {
              this.projectDescription = res.data.rows
            })
          } else if (type === '1') {
            getDemandByClient(obj).then(res => {
              this.projectDescription = res.data.rows
            })
          }
          this.$set(this.preDailyReportList[index], 'visible', true)
          this.coumt = index
        }
      },
      selectProjectDescription(sir, index, row) {
        if (sir === 'dailyReport') {
          if (this.dailyReportList[index].dailyReportType === '0') {
            this.$set(this.dailyReportList[index], 'projectAmount', row.recognizedIncome)
            this.$set(this.dailyReportList[index], 'description', row.projectName)
          } else if (this.dailyReportList[index].dailyReportType === '1') {
            this.$set(this.dailyReportList[index], 'projectAmount', row.estimatedBudget)
            this.$set(this.dailyReportList[index], 'description', row.bdName)
          }
          this.$set(this.dailyReportList[index], 'visible', false)
          this.dailyReportList[index].itemId = this.dailyReportList[index].dailyReportType === '0' ? row.projectId : this.dailyReportList[index].dailyReportType === '1' ? row.bdId : ''
        } else if (sir === 'dailyReportPlan') {
          if (this.dailyReportPlanList[index].dailyReportType === '0') {
            this.$set(this.dailyReportPlanList[index], 'projectAmount', row.recognizedIncome)
            this.$set(this.dailyReportPlanList[index], 'description', row.projectName)
          } else if (this.dailyReportPlanList[index].dailyReportType === '1') {
            this.$set(this.dailyReportPlanList[index], 'projectAmount', row.estimatedBudget)
            this.$set(this.dailyReportPlanList[index], 'description', row.bdName)
          }
          this.$set(this.dailyReportPlanList[index], 'visible', false)
          this.dailyReportPlanList[index].itemId = this.dailyReportPlanList[index].dailyReportType === '0' ? row.projectId : this.dailyReportPlanList[index].dailyReportType === '1' ? row.bdId : ''
        } else {
          if (this.preDailyReportList[index].dailyReportType === '0') {
            this.$set(this.preDailyReportList[index], 'projectAmount', row.recognizedIncome)
            this.$set(this.preDailyReportList[index], 'description', row.projectName)
          } else if (this.preDailyReportList[index].dailyReportType === '1') {
            this.$set(this.preDailyReportList[index], 'projectAmount', row.estimatedBudget)
            this.$set(this.preDailyReportList[index], 'description', row.bdName)
          }
          this.$set(this.preDailyReportList[index], 'visible', false)
          this.preDailyReportList[index].itemId = this.preDailyReportList[index].dailyReportType === '0' ? row.projectId : this.preDailyReportList[index].dailyReportType === '1' ? row.bdId : ''
        }
      },
      submit(status) {
        this.daily.dailyDate = this.dailyDate
        this.daily.status = status
        this.daily.dailyPlanDate = this.dailyPlanDate
        const obj = {
          daily: this.daily,
          dailyReportList: this.dailyReportList,
          dailyReportPlanList: this.dailyReportPlanList,
          preDailyReportList: this.preDailyReportList
        }

        if (this.dailyReportList.length <= 0) {
          this.$message.error(this.$t('myDailyDetails.message.pleaseAdd') + ' Daily Report');
          return false
        }

        if (this.dailyReportPlanList.length <= 0) {
          this.$message.error(this.$t('myDailyDetails.message.pleaseAdd') + ' Plan activity');
          return false
        }

        // action item 和 description 字数校验
        if (this.dailyReportList.length > 0) {
          for (let i = 0; i < this.dailyReportList.length; i++) {
            const j = i + 1
            if (this.dailyReportList[i].actionItem && this.dailyReportList[i].actionItem.length > 1000) {
              this.$message.error('Daily Report' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「Action Item」' + this.$t('myDailyDetails.message.moreThan') + 1000 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
            if (this.dailyReportList[i].description && this.dailyReportList[i].description.length > 1000) {
              this.$message.error('Daily Report' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「Project/Description」' + this.$t('myDailyDetails.message.moreThan') + 1000 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
            if (this.dailyReportList[i].other && this.dailyReportList[i].other.length > 255) {
              this.$message.error('Daily Report' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「Project/Description」' + this.$t('myDailyDetails.message.moreThan') + 255 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
          }
        }
        if (this.dailyReportPlanList.length > 0) {
          for (let i = 0; i < this.dailyReportPlanList.length; i++) {
            const j = i + 1
            if (this.dailyReportPlanList[i].actionItem && this.dailyReportPlanList[i].actionItem.length > 1000) {
              this.$message.error('Plan activity' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「actionItem」' + this.$t('myDailyDetails.message.moreThan') + 1000 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
            if (this.dailyReportPlanList[i].description && this.dailyReportPlanList[i].description.length > 1000) {
              this.$message.error('Plan activity' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「Project/Description」' + this.$t('myDailyDetails.message.moreThan') + 1000 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
            if (this.dailyReportPlanList[i].other && this.dailyReportPlanList[i].other.length > 255) {
              this.$message.error('Plan activity' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「Project/Description」' + this.$t('myDailyDetails.message.moreThan') + 255 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
          }
        }
        if (this.preDailyReportList && this.preDailyReportList.length > 0) {
          for (let i = 0; i < this.preDailyReportList.length; i++) {
            const j = i + 1
            if (this.preDailyReportList[i].actionItem && this.preDailyReportList[i].actionItem.length > 1000) {
              this.$message.error('Tracking item' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「actionItem」' + this.$t('myDailyDetails.message.moreThan') + 1000 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
            if (this.preDailyReportList[i].description && this.preDailyReportList[i].description.length > 1000) {
              this.$message.error('Tracking item' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「Project/Description」' + this.$t('myDailyDetails.message.moreThan') + 1000 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
            if (this.preDailyReportList[i].other && this.preDailyReportList[i].other.length > 255) {
              this.$message.error('Tracking item' + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「Project/Description」' + this.$t('myDailyDetails.message.moreThan') + 255 + this.$t('myDailyDetails.message.moreThanTwo'));
              return false
            }
          }
        }

        if (status === '0') {
          for (let i = 0; i < this.dailyReportList.length; i++) {
            if (this.dailyReportList[i].customerId === '' && this.dailyReportList[i].customerIs !== '1') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Daily Report Client ');
              return false
            }
            if (Number(this.dailyReportList[i].hrs) < 0) {
              this.$message.error('Hrs' + this.$t('myDailyDetails.message.not') + this.dailyReportList[i].hrs);
              return false
            }
          }
          for (let i = 0; i < this.dailyReportPlanList.length; i++) {
            if (this.dailyReportPlanList[i].customerId === '' && this.dailyReportPlanList[i].customerIs !== '1') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Plan activity Client ');
              return false
            }
            if (Number(this.dailyReportPlanList[i].hrs) < 0) {
              this.$message.error('Hrs' + this.$t('myDailyDetails.message.not') + this.dailyReportPlanList[i].hrs);
              return false
            }
          }
          // for (let i = 0; i < this.preDailyReportList.length; i++) {
          //   if (this.preDailyReportList[i].customerId === '' && this.preDailyReportList[i].customerIs !== '1') {
          //     this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Tracking Item Client ');
          //     return false
          //   }
          // }
        }
        if (status === '1') {
          for (let i = 0; i < this.dailyReportList.length; i++) {
            if (this.dailyReportList[i].customerId === '' && this.dailyReportList[i].customerIs !== '1') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Daily Report Client ');
              return false
            }
            if (!this.dailyReportList[i].dailyReportType || this.dailyReportList[i].dailyReportType.trim() === '') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Daily Report Type ');
              return false
            }
            if (!this.dailyReportList[i].description || this.dailyReportList[i].description.trim() === '') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Daily Report Project/Description ');
              return false
            }
            if (this.dailyReportList[i].Hrs === '') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseImport') + ' Daily Report Hrs ');
              return false
            }
            if (Number(this.dailyReportList[i].hrs) < 0) {
              this.$message.error('Hrs' + this.$t('myDailyDetails.message.not') + this.dailyReportList[i].hrs);
              return false
            }
            if (this.dailyReportList[i].actionItem === '') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseImport') + ' Action Item ');
              return false
            }
          }

          for (let i = 0; i < this.dailyReportPlanList.length; i++) {
            if (this.dailyReportPlanList[i].customerId === '' && this.dailyReportPlanList[i].customerIs !== '1') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Plan activity Client ');
              return false
            }
            if (!this.dailyReportPlanList[i].dailyReportType || this.dailyReportPlanList[i].dailyReportType.trim() === '') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Plan activity Type ');
              return false
            }
            if (!this.dailyReportPlanList[i].description || this.dailyReportPlanList[i].description.trim() === '') {
              this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Plan activity Project/Description ');
              return false
            }
            if (Number(this.dailyReportPlanList[i].hrs) < 0) {
              this.$message.error('Hrs' + this.$t('myDailyDetails.message.not') + this.dailyReportPlanList[i].hrs);
              return false
            }
          }

          // for (let i = 0; i < this.preDailyReportList.length; i++) {
          //   if (this.preDailyReportList[i].customerId === '' && this.preDailyReportList[i].customerIs !== '1') {
          //     this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Tracking Item Client ');
          //     return false
          //   }
          //   if (!this.preDailyReportList[i].dailyReportType || this.preDailyReportList[i].dailyReportType.trim() === '') {
          //     this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Tracking Item Type ');
          //     return false
          //   }
          //   if (!this.preDailyReportList[i].description || this.preDailyReportList[i].description.trim() === '') {
          //     this.$message.error(this.$t('myDailyDetails.message.pleaseSelect') + ' Tracking Item Project/Description ');
          //     return false
          //   }
          // }
        }
        if (status === '1') {
          this.$confirm(this.$t('tips.permanentUpdate'), this.$t('tips.tips'), {
            confirmButtonText: this.$t('tips.determine'),
            cancelButtonText: this.$t('tips.cancel'),
            type: 'warning'
          })
            .then(() => {
              save(obj).then(res => {
                if (res.status === 200) {
                  this.$message.success(this.$t('myDailyDetails.message.succeed'));
                  this.backPage()
                } else {
                  this.$message.error(res.message);
                  if (res.message === '邮件发送失败') {
                    this.backPage()
                  }
                }
              })
            });
        } else {
          save(obj).then(res => {
            if (res.status === 200) {
              this.$message.success(this.$t('myDailyDetails.message.succeed'));
              this.backPage()
            } else {
              this.$message.error(res.message);
              if (res.message === '邮件发送失败') {
                this.backPage()
              }
            }
          })
        }
      },
      backPageCopy() {
        if (this.isEdit) {
          this.backPage()
        } else {
          // 如果是取消就进行提示
          this.$confirm(this.$t('tips.isTure'), this.$t('tips.tips'), {
            confirmButtonText: this.$t('tips.determine'),
            cancelButtonText: this.$t('tips.cancel'),
            type: 'warning'
          }).then(() => {
            this.backPage()
          })
        }
      },
      backPage() {
        const str = '/dailyManagement/myDailyDetails'
        this.$store.getters.pageState[str] = {}
        const visitedViews = this.$store.state.tagsView.visitedViews

        visitedViews.forEach(view => {
          if (view.path === str) {
            this.$store.dispatch('delVisitedViews', view).then(views => {
              const latestView = views.slice(-1)[0]
              if (latestView) {
                console.log(latestView)
                this.$router.push(latestView)
              } else {
                this.$router.push('/')
              }
            })
          }
        })
      },
      getData() {
        const str = '/dailyManagement/myDailyDetails'
        if (this.id) {
          if (this.$store.getters.pageState[str] && this.$store.getters.pageState[str][this.id]) {
            const obj = this.$store.getters.pageState[str][this.id]
            this.daily = obj.daily
            this.isEdit = obj.isEdit
            this.dailyDate = obj.dailyDate
            this.dailyPlanDate = obj.dailyPlanDate
            this.dailyReportList = obj.dailyReportList
            this.dailyReportPlanList = obj.dailyReportPlanList
            this.preDailyReportList = obj.preDailyReportList
          } else {
            this.isDailyDate = true
            queryDetail({ id: this.id }).then(res => {
              this.daily = res.data.daily
              this.isEdit = this.daily.status === '1'
              this.dailyDate = this.daily.dailyDate
              this.dailyPlanDate = this.daily.dailyPlanDate
              this.dailyReportList = res.data.dailyReportList
              for (let y = 0; y < this.dailyReportList.length; y++) {
                this.dailyReportList[y].listIndex = y;
              }
              this.dailyReportPlanList = res.data.dailyReportPlanList
              for (let y = 0; y < this.dailyReportPlanList.length; y++) {
                this.dailyReportPlanList[y].listIndex = y;
              }
              this.preDailyReportList = res.data.preDailyReportList

              for (let y = 0; y < this.preDailyReportList.length; y++) {
                this.preDailyReportList[y].listIndex = y;
              }
              this.sumTotal()
              this.show = true
            })
          }
        } else {
          this.isDailyDate = false
          const day2 = new Date();
          day2.setTime(day2.getTime());
          const s2 = day2.getFullYear() + '-' + (day2.getMonth() + 1) + '-' + day2.getDate();
          this.dailyDate = s2
          this.changeDate()
          // 设置计划报表日期
          if (this.$store.getters.pageState[str] && this.$store.getters.pageState[str].addDaily) {
            const obj = this.$store.getters.pageState[str].addDaily
            this.daily = obj.daily
            this.isEdit = obj.isEdit
            this.dailyDate = obj.dailyDate
            this.dailyPlanDate = obj.dailyPlanDate
            this.dailyReportList = obj.dailyReportList
            this.dailyReportPlanList = obj.dailyReportPlanList
            this.preDailyReportList = obj.preDailyReportList
          }
        }
      },
      copyPlan() {
        this.$confirm('「前一日的Plan activity將被複製到本日Daily Report，是否確定執行？', '提示', {
          confirmButtonText: '確定',
          cancelButtonText: '取消'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '保存成功'
          });
          queryPlan().then(res => {
            if (res.status === 200) {
              if (res.data.length > 0) {
                for (let i = 0; i < res.data.length; i++) {
                  const dataList = {
                    hrs: res.data[i].hrs,
                    other: res.data[i].other,
                    itemId: res.data[i].itemId,
                    actionItem: res.data[i].actionItem,
                    customerId: res.data[i].customerId,
                    customerIs: res.data[i].customerIs,
                    customerName: res.data[i].customerName,
                    description: res.data[i].description,
                    dailyReportType: res.data[i].dailyReportType,
                    projectAmount: res.data[i].projectAmount
                  }
                  this.$set(this.dailyReportList, this.dailyReportList.length, dataList);
                }
              }
              this.sumTotal();
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '放弃保存'
          })
        });
      }
    },
    mounted() {
      // this.isEdit = this.$route.query.status === '1'
      console.log('dd', this.$store.getters.allDic.dailyType)
      this.dailyReportTypeListShort = this.$store.getters.allDic.dailyType.filter(v => v.label !== 'HQ')
      console.log('ddfdff', this.dailyReportTypeListShort)
      this.id = this.$route.query.id
      this.getData()
    },
    updated() { // 页面储存
      const obj = {
        pageRouting: '/dailyManagement/myDailyDetails',
        id: this.id ? this.id : 'addDaily',
        daily: this.daily,
        isEdit: this.isEdit,
        dailyDate: this.dailyDate,
        dailyPlanDate: this.dailyPlanDate,
        dailyReportList: this.dailyReportList,
        dailyReportPlanList: this.dailyReportPlanList,
        preDailyReportList: this.preDailyReportList
      }
      store.dispatch('addPageState', obj)
    }
  };
</script>
<style  lang="scss">
  .el-table--medium td, .el-table--medium th {
      padding: 5px 0;
  }
  .absolute {
    position: absolute;
    right: 20px;
    top: 7px
  }
  .yt-table-cke{
    float: left;
    margin-top: 7px;
    height: 37px;
  }
  .yt-table-picker{
    display: inline-block;
    width: 120px;
  }
</style>
